<?php

App::import('Helper', 'Message');

class MessageHelperTest extends CakeTestCase {
	
	function startTest() {
		$this->Message =& ClassRegistry::init('MessageHelper');
		$_SESSION['Auth']['User']['id'] = 1;
	}
	
	function endTest() {
		unset($this->Message);
		unset($_SESSION['Auth']['User']);
		ClassRegistry::flush();
	}
	
	function testRemoveRe() {
		$conversation = array(
			array(
				'Message' => array(
					'id' => 1,
					'parent_id' => 0,
					'user_id' => 1,
				),
				'User' => array(
					'id' => 1,
				)
			),
			array(
				'Message' => array(
					'id' => 2,
					'parent_id' => 1,
					'user_id' => 3,
				),
				'User' => array(
					'id' => 3,
				)
			),
			array(
				'Message' => array(
					'id' => 6,
					'parent_id' => 1,
					'user_id' => 1,
				),
				'User' => array(
					'id' => 1,
				)
			)
		);
		$this->assertEqual(2, $this->Message->get_reply_id($conversation));
		$_SESSION['Auth']['User']['id'] = 2;
		$conversation = array(
			array(
				'Message' => array(
					'id' => 4,
					'parent_id' => 0,
					'user_id' => 2,
				),
				'User' => array(
					'id' => 2
				)
			),
			array(
				'Message' => array(
					'id' => 5,
					'parent_id' => 4,
					'user_id' => 1,
				),
				'User' => array(
					'id' => 1
				)
			)
		);
		$this->assertEqual(5, $this->Message->get_reply_id($conversation));
		
		$_SESSION['Auth']['User']['id'] = 4;
		$conversation = array(
			array(
				'Message' => array(
					'id' => 3,
					'parent_id' => 0,
					'user_id' => 4
				),
				'User' => array(
					'id' => 4
				)
			)
		);
		$this->assertEqual(3, $this->Message->get_reply_id($conversation));
		$this->assertFalse($this->Message->get_reply_id());
	}
	
}

?>
